% Reshaping UK data output from Stata for Matlab input
clear all
UK_Budget = readmatrix('../data/DataforMatlab/UK_Budget_CPI.csv');
  
%%
I = 85; 
NL = 10000; 
T = 2017- 2001 + 1;

B_vec_L = NaN(I,NL,T);
w_vec_L = NaN(1,NL,T);
hhw_vec_L = NaN(1,NL,T);
for t = 1:T 
ind = find(UK_Budget(:,1) == 2000+t);

btmp=  UK_Budget(min(ind):max(ind),4:end)';
wtmp =  UK_Budget(min(ind):max(ind),2)';   
hhwtmp =  UK_Budget(min(ind):max(ind),3)';  

[wtmp2, wLind] = sort(wtmp);
btmp2 = btmp(:,wLind,:);
hhwtmp2 = hhwtmp(:,wLind,:);
w_vec_L(1,1:size(ind,1),t) = wtmp2;
w_vec_L(1,size(ind,1):end,t) = NaN;
B_vec_L(:,1:size(ind,1),t) = btmp2;
hhw_vec_L(1,1:size(ind,1),t) = hhwtmp2;
end

w_vec_long = reshape(log(w_vec_L),[10000,T]);

I_vec = w_vec_L;
B_vec = B_vec_L;

B_vec = B_vec./sum(B_vec);
clearvars -except I_vec B_vec w_vec_long hhw_vec_L
save ../data/DataforMatlab/UK_Budget_CPI

%%
clear
price = readmatrix('../data/DataforMatlab/p_CPI.csv');
price(:,1) = [];
pvec_tmp = price./price(1,:);
save ../data/DataforMatlab/cpi_pvec_tmp

